package com.cx.common.core.mapstrcut;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class ObjectConvertorMapper {

    public ObjectConvertorMapper() {
    }

    public List<String> String2List(String str) {
        if (StrUtil.isBlank(str)) {
            return Collections.emptyList();
        }
        return Arrays.asList(str.split(","));
    }


    public String List2String(List<String> list) {
        if (CollectionUtil.isEmpty(list)) {
            return null;
        }
        return StrUtil.join(",", list);
    }


    public List<Integer> string2listInteger(String s) {
        if (StrUtil.isBlank(s)) {
            return Collections.emptyList();
        }
        List<Integer> string2listInteger = new ArrayList<>();
        String[] ids = s.split(",");
        for (String id : ids) {
            string2listInteger.add(Integer.valueOf(id));
        }
        return string2listInteger;
    }

    public String listInteger2string(List<Integer> list) {
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return StrUtil.join(",", list);
    }

}
